#include <cstdio>
#include <cstring>
#define max(a,b) (((a)>(b))?(a):(b))
struct point
{
    int x,y;
    int t,v;
}p[205];
int N,T;
int head[ 205 ], node[ 205 ], next[ 205 ], e;
bool visit[ 205 ];

void addedge( int u, int v )
{
    node[ e ] = v; next[ e ] = head[ u ]; head[ u ] = e++;
}

int dis( point a )
{
    return a.x * a.x + a.y * a.y;
}

void init ()
{
    int i, j, minn, q;
    bool flag;
    for(int i=0;i<N;i++)
        scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v);
    e = 0;
    memset( head, -1, sizeof( head ) );
    memset( visit, 0, sizeof( visit ) );
    for ( i = 0; i < N; i++ )
    {
        flag = false;
        minn = 0x7fffffff;
        for ( j = 0; j < N; j++ )
            if ( p[ i ].x * p[ j ].y == p[ j ].x * p[ i ].y && dis( p[ i ] ) < dis( p[ j ] ) && minn > dis( p[ j ] ) )
            {
                minn = dis( p[ j ] );
                flag = true;
                q = j;
            }
        if ( flag )
        {
            visit[ q ] = 1;
            addedge( i, q );
        }
    }
}

int f[ 40001 ];

void work( )
{
    int i, j, k, tt, vv, ans = 0;
    memset( f, 0, sizeof( f ) );
    for ( i = 0; i < N; i++ )
        if ( !visit[ i ] )
        {
            for ( j = T; j >= p[ i ].t; j-- )
            {
                tt = p[ i ].t;
                vv = p[ i ].v;
                f[ j ] = max( f[ j ], f[ j - tt ] + vv );
                for ( k = head[ i ]; k != -1; k = next[ k ] )
                {
                    tt += p[ node[ k ] ].t;
                    vv += p[ node[ k ] ].v;
                    if ( j < tt ) break;
                    f[ j ] = max( f[ j ], f[ j - tt ] + vv );
                }
            }
        }
    for ( i = 0; i <= T; i++ )
        ans = max( ans, f[ i ] );
    printf("%d\n", ans);
}

int main( )
{
    int cas = 1;
    while(scanf("%d%d",&N,&T)!=EOF)
    {
        init( );
        printf("Case %d: ", cas++);
        work( );
    }
    return 0;
}
